summaryrefslogtreecommitdiff
path: root/app/[lng]/procurement/(procurement)/pq_new/[vendorId]/[submissionId]/page.tsx
blob: b4b5136335fc601b885712b0d1c7cf88d62e6c2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import * as React from "react"
import { Metadata } from "next"
import Link from "next/link"
import { notFound } from "next/navigation"
import { ArrowLeft } from "lucide-react"
import { Shell } from "@/components/shell"
import { Button } from "@/components/ui/button"
import { Badge } from "@/components/ui/badge"
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { Separator } from "@/components/ui/separator"
import { getPQById, getPQDataByVendorId } from "@/lib/pq/service"
import { unstable_noStore as noStore } from 'next/cache'
import { PQReviewWrapper } from "@/components/pq-input/pq-review-wrapper"
import { formatDate } from "@/lib/utils"

export const metadata: Metadata = {
  title: "PQ 검토",
  description: "협력업체의 Pre-Qualification 답변을 검토합니다.",
}

// 페이지가 기본적으로 동적임을 나타냄
export const dynamic = "force-dynamic"

interface PQReviewPageProps {
  params: Promise<{
    vendorId: string;
    submissionId: string;
  }>
}

export default async function PQReviewPage(props: PQReviewPageProps) {
  // 캐시 비활성화
  noStore()
  
  const params = await props.params
  const vendorId = parseInt(params.vendorId, 10)
  const submissionId = parseInt(params.submissionId, 10)
  
  try {
    // PQ Submission 정보 조회
    const pqSubmission = await getPQById(submissionId, vendorId)
    
    // PQ 데이터 조회 (질문과 답변)
    const pqData = await getPQDataByVendorId(vendorId, pqSubmission.projectId || undefined)
    
    // 프로젝트 정보 (프로젝트 PQ인 경우)
    const projectInfo = pqSubmission.projectId ? {
      id: pqSubmission.projectId,
      projectCode: pqSubmission.projectCode || '',
      projectName: pqSubmission.projectName || '',
      status: pqSubmission.status,
      submittedAt: pqSubmission.submittedAt,
    } : null
    
    // PQ 유형 및 상태 레이블
    const typeLabel = pqSubmission.type === "GENERAL" ? "일반 PQ" : 
                     pqSubmission.type === "PROJECT" ? "프로젝트 PQ" : 
                     pqSubmission.type === "NON_INSPECTION" ? "미실사 PQ" : "일반 PQ"
    const statusLabel = getStatusLabel(pqSubmission.status)
    const statusVariant = getStatusVariant(pqSubmission.status)
    
    // 수정 가능 여부 (SUBMITTED 상태일 때만 가능)
    const canReview = pqSubmission.status === "SUBMITTED"
    
    return (
      <Shell className="gap-6 max-w-5xl">
        <div className="flex items-center justify-between">
          <div className="flex items-center gap-4">
            <Button variant="outline" size="sm" asChild>
              <Link href="/procurement/pq_new">
                <ArrowLeft className="w-4 h-4 mr-2" />
                목록으로
              </Link>
            </Button>
            <div>
              <h2 className="text-2xl font-bold tracking-tight">
                {pqSubmission.vendorName} - {typeLabel}
              </h2>
              <div className="flex items-center gap-2 mt-1">
                <Badge variant={statusVariant}>{statusLabel}</Badge>
                {projectInfo && (
                  <span className="text-muted-foreground">
                    {projectInfo.projectName} ({projectInfo.projectCode})
                  </span>
                )}
              </div>
            </div>
          </div>
        </div>
        
        {/* 상태별 알림 */}
        {pqSubmission.status === "SUBMITTED" && (
          <Alert>
            <AlertTitle>제출 완료</AlertTitle>
            <AlertDescription>
              협력업체가 {formatDate(pqSubmission.submittedAt, "kr")}에 PQ를 제출했습니다. 검토 후 승인 또는 거부할 수 있습니다.
            </AlertDescription>
          </Alert>
        )}
        
        {pqSubmission.status === "APPROVED" && (
          <Alert variant="success">
            <AlertTitle>승인됨</AlertTitle>
            <AlertDescription>
              {formatDate(pqSubmission.approvedAt, "kr")}에 승인되었습니다.
            </AlertDescription>
          </Alert>
        )}
        
        {pqSubmission.status === "REJECTED" && (
          <Alert variant="destructive">
            <AlertTitle>거부됨</AlertTitle>
            <AlertDescription>
              {formatDate(pqSubmission.rejectedAt, "kr")}에 거부되었습니다.
              {pqSubmission.rejectReason && (
                <div className="mt-2">
                  <strong>사유:</strong> {pqSubmission.rejectReason}
                </div>
              )}
            </AlertDescription>
          </Alert>
        )}
        
        <Separator />
        
        {/* PQ 검토 컴포넌트 */}
        <Tabs defaultValue="review" className="w-full">
          <TabsList>
            <TabsTrigger value="review">PQ 검토</TabsTrigger>
            <TabsTrigger value="vendor-info">협력업체 정보</TabsTrigger>
          </TabsList>
          
          <TabsContent value="review" className="mt-4">
            <PQReviewWrapper
              pqData={pqData}
              vendorId={vendorId}
              pqSubmission={pqSubmission}
              canReview={canReview}
            />
          </TabsContent>
          
          <TabsContent value="vendor-info" className="mt-4">
            <div className="rounded-md border p-4">
              <h3 className="text-lg font-medium mb-4">협력업체 정보</h3>
              <div className="grid grid-cols-2 gap-4">
                <div>
                  <p className="text-sm font-medium text-muted-foreground">업체명</p>
                  <p>{pqSubmission.vendorName}</p>
                </div>
                <div>
                  <p className="text-sm font-medium text-muted-foreground">업체 코드</p>
                  <p>{pqSubmission.vendorCode}</p>
                </div>
                <div>
                  <p className="text-sm font-medium text-muted-foreground">상태</p>
                  <p>{pqSubmission.vendorStatus}</p>
                </div>
                {/* 필요시 추가 정보 표시 */}
              </div>
            </div>
          </TabsContent>
        </Tabs>
      </Shell>
    )
  } catch (error) {
    console.error("Error loading PQ:", error)
    notFound()
  }
}

// 상태 레이블 함수
function getStatusLabel(status: string): string {
  switch (status) {
    case "REQUESTED":
      return "요청됨";
    case "IN_PROGRESS":
      return "진행 중";
    case "SUBMITTED":
      return "제출됨";
    case "APPROVED":
      return "승인됨";
    case "REJECTED":
      return "거부됨";
    default:
      return status;
  }
}

// 상태별 Badge 스타일
function getStatusVariant(status: string): "default" | "outline" | "secondary" | "destructive" | "success" {
  switch (status) {
    case "REQUESTED":
      return "outline";
    case "IN_PROGRESS":
      return "secondary";
    case "SUBMITTED":
      return "default";
    case "APPROVED":
      return "success";
    case "REJECTED":
      return "destructive";
    default:
      return "outline";
  }
}